import { baseRequestClient } from './request';

/** 分类树节点 */
export interface CategoryNode {
  id: string;
  name: string;
  level: number;
  parentId: string;
  children?: CategoryNode[];
}

/** 分类树响应 */
export interface CategoryTreeRes {
  code: number;
  data: CategoryNode[];
  message: string;
  status: boolean;
  success: boolean;
  timestamp: number;
}

/**
 * 获取分类树（GET /category/tree）
 */
export async function getCategoryTree() {
  const res = await baseRequestClient.get<CategoryTreeRes>('/category/tree');
  return res?.data;
}

/** 新增分类入参 */
export interface AddCategoryPayload {
  name: string;
  parentId: string;
}

/**
 * 新增分类（POST /category/add）
 */
export async function addCategory(payload: AddCategoryPayload) {
  const res = await baseRequestClient.post('/category/add', payload);
  return res?.data;
}

/** 更新分类入参 */
export interface UpdateCategoryPayload {
  id: string;
  name: string;
}

/**
 * 更新分类（POST /category/update）
 */
export async function updateCategory(payload: UpdateCategoryPayload) {
  const res = await baseRequestClient.post('/category/update', payload);
  return res?.data;
}

/**
 * 删除分类（DELETE /category/{id}）
 */
export async function deleteCategory(id: string) {
  const res = await baseRequestClient.delete(`/category/${id}`);
  return res?.data;
}